#include "processbar.h"

#define FILE_SIZE 1024*1024*1024

// 模拟下载任务
void download()
{
    srand(time(NULL)^1023);
    int total = FILE_SIZE;
    
    while (total)
    {
        usleep(50000);
        int one = rand()%(4 * 1024 * 1024);
        total -= one;
        if (total < 0)
            total = 0;
        
        int download = FILE_SIZE - total;
        double rate = (download * 1.0 / (FILE_SIZE)) * 100;
        // double rate = (download * 1.0 / FILE_SIZE) * 100; // error
        // download * 1.0 / 1024 * 1024 * 1024 // 错的很明显
        
        printf("download:%f%%\n", rate);
    }
}


int main()
{
    // process1();
    //
    download();
    return 0;
}


